/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "log/Log.h"
#include "stub.h"
#include "ArchiveDownloadFile.h"
// #include "host_archive/HostArchiveRestore.h"
// #include "host_restore/HostRestore.h"
#include "Backup.h"
#include "ScanMgr.h"
#include "PluginUtilities.h"
#include "NasArchiveRestore.h"
#include "statistics/ShareResourceManager.h"
#include "SmbContextWrapper.h"
#include "SnapdiffService.h"
#include "nas_share/backup/HetroBackupJob.h"
#include "nas_share/common/HetroCommonService.h"
#include "device_access/dorado/DoradoBlock.h"
#include "common/File.h"
#include "ArchiveClient.h"

using ::testing::_;
using ::testing::AtLeast;
using testing::DoAll;
using testing::InitGoogleMock;
using ::testing::Return;
using ::testing::Sequence;
using ::testing::SetArgReferee;
using ::testing::Throw;
// using namespace FilePlugin;
using namespace std;
using namespace FS_Backup;
using namespace Module;

namespace {
// const int SUCCESS = 0;
// const int FAILED = -1;

struct FileSetInfo {
    std::string filters;
    std::string paths;
    std::string templateId;
    std::string templateName;
    std::string shareMode;
    std::string shareIp;

    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(filters, filters)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(paths, paths)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(templateId, templateId)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(templateName, templateName)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(shareMode, shareMode)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(shareIp, shareIp)
    END_SERIAL_MEMEBER
};

struct IpPort {
    std::string ip;
    int port { -1 };
    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(ip, ip)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(port, port)
    END_SERIAL_MEMEBER
};

struct ExtendArchiveInfo {
    std::vector<IpPort> serviceInfo;
    bool enableSSL {false};
    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(enableSSL, enable_ssl)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(serviceInfo, service_info)
    END_SERIAL_MEMEBER
};

// formatTypeTag: 控制formatType，从而控制m_isAggCopy
AppProtect::RestoreJob RestoreJobInfoSetUp(bool formatTypeTag, string FileOrShare)
{
    AppProtect::RestoreJob restoreJob;
    restoreJob.requestId = "123456789";
    restoreJob.jobId = "111111";
    restoreJob.targetEnv.id = "123";
    restoreJob.targetEnv.name = "123";
    restoreJob.targetEnv.port = 8088;
    restoreJob.targetEnv.auth.authkey = "admin";
    restoreJob.targetEnv.auth.authPwd = "Huawei@123456789";
    restoreJob.targetEnv.subType = "1";
    restoreJob.targetObject.id = "123";
    restoreJob.targetObject.name = "123";
    restoreJob.targetObject.parentId =" 4564654645564";
    restoreJob.targetObject.parentName = "test_filesystem";
    // restoreJob.targetObject.subType ="NasShare";  // 控制参数
    restoreJob.targetObject.subType = FileOrShare;
    restoreJob.targetEnv.endpoint = "127.0.0.1";
    restoreJob.targetObject.auth.authkey = "admin";
    restoreJob.targetObject.auth.authPwd = "Huawei@123456789";
    // restoreJob.targetObject.extendInfo = "{\"authMode\":\"1\",\"filters\":\"\",\"ip\":\"10.28.12.144\""
    //                                      ",\"kerberosId\":\"0\",\"shareMode\":\"1\"}";
    
    FileSetInfo fileSetInfo;
    fileSetInfo.filters = "";
    fileSetInfo.paths = "[{\"name\":\"/l30015744_restore\"}]";
    fileSetInfo.templateId = "";
    fileSetInfo.templateName = "";
    fileSetInfo.shareMode = "0";
    fileSetInfo.shareIp = "192.168.34.52";

    std::string filesetInfoStr;
    Module::JsonHelper::StructToJsonString(fileSetInfo, filesetInfoStr);
    restoreJob.targetEnv.extendInfo = filesetInfoStr;
    restoreJob.targetObject.extendInfo = filesetInfoStr;

    std::string path = "/MetaFS/cache";
    HostAddress hostadd;
    hostadd.ip="10.28.12.144";
    StorageRepository cacheRepo;
    cacheRepo.repositoryType = RepositoryDataType::CACHE_REPOSITORY;
    cacheRepo.path.push_back(path);
    cacheRepo.remotePath = "/MetaFS/cache";
    cacheRepo.remoteHost.push_back(hostadd);
    cacheRepo.auth.authkey = "admin";
    cacheRepo.auth.authPwd = "Admin@123";
    cacheRepo.endpoint.ip = "10.28.12.144";
    cacheRepo.endpoint.port = 8088;
    StorageRepository dataRepo;
    dataRepo.repositoryType = RepositoryDataType::DATA_REPOSITORY;
    dataRepo.remotePath = "/BackupFS";
    dataRepo.path.push_back(dataRepo.remotePath);
    dataRepo.remoteHost.push_back(hostadd);
    dataRepo.auth.authkey = "admin";
    dataRepo.auth.authPwd = "Admin@123";
    dataRepo.endpoint.ip = "10.28.12.144";
    dataRepo.endpoint.port = 8088;
    dataRepo.protocol = RepositoryProtocolType::type::S3;

    ExtendArchiveInfo archiveInfo;

    IpPort port;
    port.ip = "192.168.34.52";
    port.port = 57577;

    archiveInfo.serviceInfo.push_back(port);
    archiveInfo.enableSSL = false;

    std::string archiveInfoStr;
    Module::JsonHelper::StructToJsonString(archiveInfo, archiveInfoStr);

    dataRepo.extendInfo = archiveInfoStr;
    StorageRepository metaRepo;
    metaRepo.repositoryType = RepositoryDataType::META_REPOSITORY;
    path = "/MetaFS/meta";
    metaRepo.path.push_back(path);
    metaRepo.remotePath = "/MetaFS/meta";
    metaRepo.remoteHost.push_back(hostadd);
    metaRepo.auth.authkey = "admin";
    metaRepo.auth.authPwd = "Admin@123";
    metaRepo.endpoint.ip = "10.28.12.144";
    metaRepo.endpoint.port = 8088;

    Copy copy;
    copy.repositories.push_back(cacheRepo);
    copy.repositories.push_back(dataRepo);
    copy.repositories.push_back(metaRepo);
    copy.id = "copyId";
    copy.protectObject.id = "CopyProtectObjectId";
    copy.protectObject.subType = FileOrShare;  //控制参数
    if (formatTypeTag) {
        copy.formatType = CopyFormatType::type::INNER_DIRECTORY;
    }
    restoreJob.copies.push_back(copy);
    restoreJob.extendInfo = "{\"failed_script\":\"\",\"post_script\":\"\",\"pre_script\":\"\","
                           "\"restoreOption\":\"SKIP\", \"protocol\":\"0\"}";
    return restoreJob;
}
}

namespace Archive_Test {
    class BackupTest : public Backup {
    public:
        explicit BackupTest(const BackupParams& backupParams);
        BackupTest(std::string source, std::string destination);
        ~BackupTest() override;

        BackupRetCode Start() override;
        BackupRetCode Abort() override;
        BackupRetCode Destroy() override;
        BackupRetCode Enqueue(std::string contrlFile) override;
        BackupPhaseStatus GetStatus() override;
        BackupStats GetStats() override;
        std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
    };


    BackupTest::BackupTest(const BackupParams& backupParams) :  Backup(backupParams) {};

    BackupTest::~BackupTest() {};

    BackupRetCode BackupTest::Start() {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode BackupTest::Abort() {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode BackupTest::Destroy() {
        return BackupRetCode::SUCCESS;
    }
    BackupRetCode BackupTest::Enqueue(std::string contrlFile) {
        return BackupRetCode::SUCCESS;
    }
    BackupPhaseStatus BackupTest::GetStatus() {
        return BackupPhaseStatus::COMPLETED;
    }
    BackupStats BackupTest::GetStats() {
        BackupStats backupStats;
        return backupStats;
    }
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> BackupTest::GetFailedDetails() {
        std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
        return ret;
    }
    class ScanTest : public Scanner {
    public:
        explicit ScanTest(const ScanConfig& scanConfig);
        ~ScanTest() override;

        SCANNER_STATUS Start() override;
        SCANNER_STATUS Abort() override;
        SCANNER_STATUS Destroy() override;
        SCANNER_STATUS Enqueue(const std::string& directory, const std::string& prefix = "", uint8_t filterFlag = 0) override;
        SCANNER_STATUS EnqueueV2(const std::string& directory) override;
        SCANNER_STATUS GetStatus() override;
        ScanStatistics GetStatistics() override;
        ErrRecorder QueryFailure() override;
    };

    ScanTest::ScanTest(const ScanConfig& scanConfig) : Scanner(scanConfig) {};

    ScanTest::~ScanTest() {};

    SCANNER_STATUS ScanTest::Start() {
        return SCANNER_STATUS::SUCCESS;
    }
    SCANNER_STATUS ScanTest::Abort() {
        return SCANNER_STATUS::SUCCESS;
    }
    SCANNER_STATUS ScanTest::Destroy() {
        return SCANNER_STATUS::SUCCESS;
    }
    SCANNER_STATUS ScanTest::Enqueue(const std::string& directory, const std::string& prefix, uint8_t filterFlag) {
        return SCANNER_STATUS::SUCCESS;
    }
    SCANNER_STATUS ScanTest::EnqueueV2(const std::string& directory) {
        return SCANNER_STATUS::SUCCESS;
    }
    SCANNER_STATUS ScanTest::GetStatus() {
        return SCANNER_STATUS::COMPLETED;
    }
    ScanStatistics ScanTest::GetStatistics() {
        ScanStatistics scanStats {};
        return scanStats;
    }

    ErrRecorder ScanTest::QueryFailure() {
        ErrRecorder errRecorder {};
        return errRecorder;
    }
}// namespace archive_test

static unique_ptr<FS_Backup::Backup> CreateBackupInstStub_Succ(void* obj, BackupParams backupParams) {
    BackupParams emptyInfo;
    return std::make_unique<Archive_Test::BackupTest>(emptyInfo);
}

static unique_ptr<Scanner> CreateScanInstStub_Succ(void* obj, const ScanConfig& scanConfig) {
    ScanConfig emptInfo;
    unique_ptr<Scanner> scanInst = std::make_unique<Archive_Test::ScanTest>(emptInfo);
    return scanInst;
}

static AppProtect::SubJob GetSubJob()
{
    AppProtect::SubJob subJob;
    subJob.jobId = "jobId123";
    subJob.subJobId = "subJob123";
    subJob.jobName = "subJob";
    subJob.jobPriority = 1;
    subJob.ignoreFailed = true;
    subJob.execNodeId = "abcde";
    subJob.jobInfo = "{\"ControlFile\":\"/cache/livemount-job/scan/ctrl\","
                    "\"SubTaskType\":1,"
                    "\"Ext\":\"abc\"}";
    return subJob;
}

static void StubFunction_VOID(void *ob)
{}

static bool StubFunction_TRUE(void *ob)
{
    return true;
}

class NasArchiveRestoreTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUpResourceManagerFunc();
    std::unique_ptr<NasArchiveRestore> m_restoreJob = std::make_unique<NasArchiveRestore>();
    Stub stub;
};

void NasArchiveRestoreTest::SetUpResourceManagerFunc()
{
    stub.set(ADDR(ShareResourceManager, SetResourcePath), StubFunction_TRUE);

    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        BackupStatistic&))ADDR(ShareResourceManager,InitResource), StubFunction_TRUE);
    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        HetroNativeScanStatistics&))ADDR(ShareResourceManager,InitResource), StubFunction_TRUE);

    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        BackupStatistic&))ADDR(ShareResourceManager,QueryResource), StubFunction_TRUE);
    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        HetroNativeScanStatistics&))ADDR(ShareResourceManager,QueryResource), StubFunction_TRUE);

    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        HetroNativeBackupStats&))ADDR(ShareResourceManager, InitResource), StubFunction_TRUE);
    stub.set((bool(ShareResourceManager::*)(const std::string &, HetroNativeBackupStats&))
        ADDR(ShareResourceManager, QueryResource), StubFunction_TRUE);

    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        BackupStatistic&))ADDR(ShareResourceManager,UpdateResource), StubFunction_TRUE);
    stub.set((bool(ShareResourceManager::*)(ShareResourceType, const std::string &,
        HetroNativeScanStatistics&))ADDR(ShareResourceManager,UpdateResource), StubFunction_TRUE);
    stub.set(ADDR(ShareResourceManager, RemoveResourceCache), StubFunction_VOID);
    stub.set(ADDR(ShareResourceManager, DeleteResource), StubFunction_TRUE);
    stub.set(ADDR(ShareResourceManager, Wait), StubFunction_VOID);
    stub.set(ADDR(ShareResourceManager, Signal), StubFunction_VOID);
}

static void Stub_AddNewJob_SUCCESS(ActionResult& returnValue, void *obj)
{
    returnValue.code = Module::SUCCESS;
}

static int stubInitClient(void* obj, const std::vector<std::string>& ipList, int port, bool enableSSL)
{
    return SUCCESS;
}

static int StubClientDisconnect(void* obj)
{
    return SUCCESS;
}

static int StubClientDisconnectFailed(void* obj)
{
    return FAILED;
}

static int ArchiveStreamService_Init_SUCCESS(void* obj)
{
    return SUCCESS;
}

static int ArchiveStreamService_Connect_SUCCESS(void* obj)
{
    return SUCCESS;
}

static int ArchiveStreamService_PrepareRecovery_SUCCESS(void* obj)
{
    return SUCCESS;
}

static int ArchiveStreamService_Disconnect_SUCCESS(void* obj)
{
    return SUCCESS;
}

static int ArchiveStreamService_EndRevocer_SUCCESS(void* obj)
{
    return SUCCESS;
}

static bool stub_IsDirExist(const string& pathName)
{
    return true;
}

static bool stub_IsDirExist_Failed(const string& pathName)
{
    return false;
}

static bool Stub_CheckConnectSMB(const std::string& ip, Module::SmbVersion version)
{
    return true;
}

static void returnVoid_Stub(void* obj)
{
    return;
}

static int ConfigReaderGetInt_Stub(void *ob, const string& sectionName, const string& keyName, bool logFlag = true)
{
    return 1;
}

static bool StubOperateIpsRule(std::vector<std::string>& ipList, const std::string& operation)
{
    return true;
}

void NasArchiveRestoreTest::SetUp()
{
    // AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp();
    // auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    // m_restoreJob->SetJobInfo(jobInfoRestore);
    stub.set(sleep, returnVoid_Stub);
    stub.set(ADDR(JobService, ReportJobDetails), StubFunction_VOID);
    stub.set(ADDR(JobService, AddNewJob), Stub_AddNewJob_SUCCESS);
    stub.set(PluginUtils::CreateDirectory, StubFunction_TRUE);
    stub.set(ADDR(ArchiveStreamService, Init), ArchiveStreamService_Init_SUCCESS);
    stub.set(ADDR(ArchiveStreamService, Connect), ArchiveStreamService_Connect_SUCCESS);
    stub.set(ADDR(ArchiveStreamService, PrepareRecovery), ArchiveStreamService_PrepareRecovery_SUCCESS);
    stub.set(ADDR(NasArchiveRestore, CheckConnectSMB), Stub_CheckConnectSMB);
    stub.set(ADDR(HetroCommonService, CreateBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(HetroCommonService, GetBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(HetroCommonService, UpdateBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(HetroCommonService, DeleteBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(HetroCommonService, UnlockBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(HetroCommonService, LockBackupStatsResource), StubFunction_TRUE);
    stub.set(ADDR(Module::ConfigReader, getInt), ConfigReaderGetInt_Stub);
    stub.set(ADDR(PluginUtils, OperateIpsRule), StubOperateIpsRule);

    SetUpResourceManagerFunc();
    AppProtect::SubJob subJob = GetSubJob();
    m_restoreJob->SetSubJob(std::make_shared<SubJob>(subJob));
}

void NasArchiveRestoreTest::TearDown() 
{
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(ADDR(JobService, AddNewJob));
    stub.reset(PluginUtils::CreateDirectory);
    stub.reset(ADDR(ArchiveStreamService, Init));
    stub.reset(ADDR(ArchiveStreamService, Connect));
    stub.reset(ADDR(ArchiveStreamService, PrepareRecovery));
    stub.reset(ADDR(NasArchiveRestore, CheckConnectSMB));
}

void NasArchiveRestoreTest::SetUpTestCase() {}
void NasArchiveRestoreTest::TearDownTestCase() {}

int TestReturnSuccess()
{
    return SUCCESS;
}

int TestReturnFailed()
{
    return FAILED;
}

static int Stub_PostJobInner_TRUE(void*)
{
    return SUCCESS;
}

static int Stub_EndRecover_TRUE(void*)
{
    return SUCCESS;
}

static int Stub_Disconnect_TRUE(void*)
{
    return SUCCESS;
}

static bool Stub_ReturnValueBoolNoParam_SUCCESS(void* obj)
{
    return true;
}

static int ArchiveStreamService_Init_SUCCESS(void* obj, const std::string &backupId, const std::string &taskID, const std::string &dirList)
{
    return MP_SUCCESS;
}

static int ArchiveStreamService_Init_FAILED(void* obj, const std::string &backupId, const std::string &taskID, const std::string &dirList)
{
    return MP_FAILED;
}

static int ArchiveStreamService_Connect_SUCCESS(void* obj, const std::string &busiIp, int busiPort, bool openSsl)
{
    return MP_SUCCESS;
}

static int ArchiveStreamService_Connect_FAILED(void* obj, const std::string &busiIp, int busiPort, bool openSsl)
{
    return MP_FAILED;
}

static bool PluginUtils_Remove_True(void* obj)
{
    return true;
}

static bool PluginUtils_Remove_False(void* obj)
{
    return false;
}

static bool PluginUtils_CreateDirectory_True(void* obj)
{
    return true;
}

static bool PluginUtils_CreateDirectory_False(void* obj)
{
    return false;
}

/*
 * 用例名称: CheckPrerequisiteJob
 * 前置条件：
 * check点：前置任务成功
 */
TEST_F(NasArchiveRestoreTest, CheckPrerequisiteJob)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    // 打桩 isDirExist
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    int ret = m_restoreJob->PrerequisiteJob();
    EXPECT_EQ(ret, SUCCESS);
    stub.reset(PluginUtils::IsDirExist);
}

// 以下几个用例通过控制参数，来覆盖不同的分支。
/*
 * 用例名称: CheckPrerequisiteJobNoDir
 * 前置条件：
 * check点：前置任务因为目录不存在失败
 */
TEST_F(NasArchiveRestoreTest, CheckPrerequisiteJobNoDir)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    // 打桩 isDirExist
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist_Failed);
    int ret = m_restoreJob->PrerequisiteJob();
    EXPECT_EQ(ret, FAILED);
    stub.reset(PluginUtils::IsDirExist);
}

/*
 * 用例名称: CheckPrerequisiteJobformatType
 * 前置条件：
 * check点：前置任务成功
 */
TEST_F(NasArchiveRestoreTest, CheckPrerequisiteJobformatType)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(true, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    // 打桩 isDirExist
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    int ret = m_restoreJob->PrerequisiteJob();
    EXPECT_EQ(ret, SUCCESS);
    stub.reset(PluginUtils::IsDirExist);
}

/*
 * 用例名称: CheckPrerequisiteJobFile
 * 前置条件：
 * check点：前置任务成功
 */
TEST_F(NasArchiveRestoreTest, CheckPrerequisiteJobFile)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasFileSystem");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    // 打桩 isDirExist
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    int ret = m_restoreJob->PrerequisiteJob();
    EXPECT_EQ(ret, SUCCESS);
    stub.reset(PluginUtils::IsDirExist);
}

/*
 * 用例名称: CheckPrerequisiteJobNoCopy
 * 前置条件：
 * check点：前置任务因为缺乏Copy失败
 */
TEST_F(NasArchiveRestoreTest, CheckPrerequisiteJobNoCopy)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    // 打桩 isDirExist
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    int ret = m_restoreJob->PrerequisiteJob();
    EXPECT_EQ(ret, FAILED);
    stub.reset(PluginUtils::IsDirExist);
}

/*
 * 用例名称: CheckGenerateSubJob
 * 前置条件：
 * check点：生成子任务成功
 */
// TEST_F(NasArchiveRestoreTest, CheckGenerateSubJob)
// {
    // AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    // auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    // m_restoreJob->SetJobInfo(jobInfoRestore);
    // stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    // // stub.set(ADDR(HostArchiveRestore, DownloadMetaFile), StubFunction_VOID);
    // int ret = m_restoreJob->GenerateSubJob();
    // EXPECT_EQ(ret, SUCCESS);
    // stub.reset(PluginUtils::IsDirExist);
// }

static SCANNER_STATUS Stub_GetStatus_Init(void* obj)
{
    return SCANNER_STATUS::INIT;
}
/*
 * 用例名称: MonitorScan
 * 前置条件：
 * check点：监控scanner
 */
TEST_F(NasArchiveRestoreTest, MonitorScan)
{
    ScanConfig scanConfig;
    m_restoreJob->m_scanner = ScanMgr::CreateScanInst(scanConfig);
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    typedef SCANNER_STATUS (*fptr)(Scanner*);
    // fptr A_foo = (fptr)(&Scanner::GetStatus);
    // stub.set(A_foo, Stub_GetStatus_Init);
    EXPECT_NO_THROW(m_restoreJob->MonitorScan());
    m_restoreJob->m_scanner->Destroy();
}

static bool Stub_IsAbort_True(void* obj)
{
    return true;
}
static bool Stub_IsAbort_False(void* obj)
{
    return false;
}
/*
 * 用例名称: MonitorScan
 * 前置条件：
 * check点：监控scanner
 */
// TEST_F(NasArchiveRestoreTest, MonitorScan2)
// {
//     ScanConfig scanConfig;
//     m_restoreJob->m_scanMgr.Initiate(scanConfig);
//     AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
//     auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
//     m_restoreJob->SetJobInfo(jobInfoRestore);
//     m_restoreJob->InitInfo();

//     m_restoreJob->m_jobState = ArchiveJobState::RUNNING;
//     m_restoreJob->m_jobId = "aa";
//     m_restoreJob->m_subJobId = "aabb";

//     stub.set(ADDR(NasArchiveRestore, IsAbort), Stub_IsAbort_True);
//     EXPECT_NO_THROW(m_restoreJob->MonitorScan());
//     stub.reset(ADDR(NasArchiveRestore, IsAbort));
//     m_restoreJob->m_scanMgr.Destroy();
// }

/*
 * 用例名称: MonitorScan
 * 前置条件：
 * check点：监控scanner
 */
//  MonitorScan进入while(true)死循环中，没法退出，故该分支没法进入。
// TEST_F(NasArchiveRestoreTest, MonitorScan3)
// {
//     ScanConfig scanConfig;
//     m_restoreJob->m_scanner = ScanMgr::CreateScanInst(scanConfig);
//     AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
//     auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
//     m_restoreJob->SetJobInfo(jobInfoRestore);
//     m_restoreJob->InitInfo();

//     m_restoreJob->m_jobState = ArchiveJobState::RUNNING;
//     m_restoreJob->m_jobId = "aa";
//     m_restoreJob->m_subJobId = "aabb";

//     stub.set(ADDR(NasArchiveRestore, IsAbort), Stub_IsAbort_False);
//     stub.set(ADDR(NasArchiveRestore, CreateSubTasksFromCtrlFile), Stub_IsAbort_False);

//     EXPECT_NO_THROW(m_restoreJob->MonitorScan());
//     stub.reset(ADDR(NasArchiveRestore, IsAbort));
//     stub.reset(ADDR(NasArchiveRestore, CreateSubTasksFromCtrlFile));
// }

static bool GetFileListInDirectoryStub(const std::string &path, std::vector<std::string> &fileList)
{
    std::string tmp_path = "/MetaFS/cache/statistics/subJob123_backup_stats.json";
    fileList.push_back(tmp_path);
    tmp_path = "/MetaFS/cache/statistics/subJob123_scan_stats.json";
    fileList.push_back(tmp_path);
    return true;
}

/*
 * 用例名称: CheckExecuteSubJob
 * 前置条件：
 * check点：执行任务成功
 */
TEST_F(NasArchiveRestoreTest, CheckExecuteSubJob)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectoryStub);
    int ret = m_restoreJob->ExecuteSubJob();
    EXPECT_EQ(ret, SUCCESS);
    stub.reset(PluginUtils::IsDirExist);
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称: CheckPostJob
 * 前置条件：
 * check点：后置任务成功
 */
TEST_F(NasArchiveRestoreTest, CheckPostJob)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    stub.set(PluginUtils::IsDirExist, stub_IsDirExist);
    stub.set(ADDR(ArchiveStreamService, EndRecover), ArchiveStreamService_EndRevocer_SUCCESS);
    int ret = m_restoreJob->PostJob();
    EXPECT_EQ(ret, SUCCESS);
    stub.reset(PluginUtils::IsDirExist);
    stub.reset(ADDR(ArchiveStreamService, EndRecover));
}

/*
 * 用例名称: CheckUnzipMetafileZip
 * 前置条件：
 * check点：UnzipMetafileZip失败
 */
TEST_F(NasArchiveRestoreTest, CheckUnzipMetafileZip)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    const std::string filemetaZipPath = "/metafile/filemeta.zip";

    EXPECT_EQ(m_restoreJob->UnzipOldMetafileZip(filemetaZipPath), false);

    stub.set(PluginUtils::Remove, PluginUtils_Remove_False);
    stub.set(PluginUtils::CreateDirectory, PluginUtils_CreateDirectory_False);
    EXPECT_EQ(m_restoreJob->UnzipOldMetafileZip(filemetaZipPath), false);
    stub.reset(PluginUtils::Remove);
    stub.reset(PluginUtils::CreateDirectory);

    stub.set(PluginUtils::Remove, PluginUtils_Remove_True);
    stub.set(PluginUtils::CreateDirectory, PluginUtils_CreateDirectory_True);
    stub.set(PluginUtils::IsFileExist, stub_IsDirExist);
    EXPECT_EQ(m_restoreJob->UnzipOldMetafileZip(filemetaZipPath), false);
    stub.reset(PluginUtils::Remove);
    stub.reset(PluginUtils::CreateDirectory);
    stub.reset(PluginUtils::IsFileExist);

    // string name  = "w/";
    // EXPECT_TRUE(m_jobPtr->IsDir(name));
}

/*
 * 用例名称: CheckReportPostJob
 * 前置条件：
 * check点：m_jobState不同状态的失败
 */
TEST_F(NasArchiveRestoreTest, CheckReportPostJob)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    m_restoreJob->m_jobState = {ArchiveJobState::PARTIAL_SUCCESS};
    m_restoreJob->ReportPostJob();

    m_restoreJob->m_jobState = {ArchiveJobState::FAILED};
    m_restoreJob->ReportPostJob();

    m_restoreJob->m_jobState = {ArchiveJobState::NONE};
    m_restoreJob->ReportPostJob();

    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckReportGenerateSubJob
 * 前置条件：
 * check点：m_jobState不同状态的失败
 */
TEST_F(NasArchiveRestoreTest, CheckReportGenerateSubJob)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    
    m_restoreJob->m_scanStats.m_totFailedDirs = 1;

    m_restoreJob->m_jobState = {ArchiveJobState::SUCCESS};
    m_restoreJob->ReportGenerateSubJob();

    m_restoreJob->m_jobState = {ArchiveJobState::FAILED};
    m_restoreJob->ReportGenerateSubJob();
    
    m_restoreJob->m_jobState = {ArchiveJobState::ABORT};
    m_restoreJob->ReportGenerateSubJob();

    m_restoreJob->m_jobState = {ArchiveJobState::EMPTY_COPY};
    m_restoreJob->ReportGenerateSubJob();

    m_restoreJob->m_jobState = {ArchiveJobState::NONE};
    m_restoreJob->ReportGenerateSubJob();

    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckIsBackupStatusInprogress
 * 前置条件：
 * check点：根据m_backupStatus不同状态成功/失败
 */
TEST_F(NasArchiveRestoreTest, CheckIsBackupStatusInprogress)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    // auto obj_backup = std::make_unique<NasArchiveRestore>();
    SubJobStatus::type jobStatus = SubJobStatus::RUNNING;
    m_restoreJob->m_backupStatus = BackupPhaseStatus::FAILED;
    EXPECT_FALSE(m_restoreJob->IsBackupStatusInprogress(jobStatus));

    m_restoreJob->m_backupStatus = BackupPhaseStatus::ABORTED;
    EXPECT_FALSE(m_restoreJob->IsBackupStatusInprogress(jobStatus));

    m_restoreJob->m_backupStatus = BackupPhaseStatus::ABORT_INPROGRESS;
    EXPECT_TRUE(m_restoreJob->IsBackupStatusInprogress(jobStatus));

    m_restoreJob->m_backupStatus = BackupPhaseStatus::INPROGRESS;
    EXPECT_TRUE(m_restoreJob->IsBackupStatusInprogress(jobStatus));
}

/*
 * 用例名称: CheckSendJobReportForAliveness
 * 前置条件：
 * check点：SendJobReportForAliveness成功
 */
TEST_F(NasArchiveRestoreTest, CheckSendJobReportForAliveness)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    EXPECT_TRUE(m_restoreJob->SendJobReportForAliveness());
}

static bool Stub_ScanMgrInitiate_False(void* obj)
{
    return false;
}

static std::unique_ptr<Scanner> Stub_CreateScanInst_nullptr(void* obj)
{
    return nullptr;
}
/*
 * 用例名称: StartScanner_False
 * 前置条件：
 * check点：扫描失败
 */
TEST_F(NasArchiveRestoreTest, StartScanner_False)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    ScanConfig config;
    m_restoreJob->m_jobId = "mm";
    m_restoreJob->m_scanInputMetePath = "/zm";
    m_restoreJob->m_scanControlFilePath = "/user";
    m_restoreJob->m_jobInfoPtr = make_shared<RestoreJob>(restoreJob);
    stub.set(ADDR(ScanMgr, CreateScanInst), Stub_CreateScanInst_nullptr);
    bool ret = m_restoreJob->StartScanner();
    EXPECT_EQ(ret, false);
    stub.reset(ADDR(ScanMgr, CreateScanInst));
}

static int Stub_CreateScanInst_False(void* obj)
{
    return -1;
}
static SCANNER_STATUS Stub_Start_False(void* obj)
{
    return SCANNER_STATUS::FAILED;
}

/*
 * 用例名称: CheckIsDir
 * 前置条件：无
 * check点：检测该目录是否存在
 */
TEST_F(NasArchiveRestoreTest, CheckIsDir)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    string name = "/ll/";
    bool ret = m_restoreJob->IsDir(name);
    EXPECT_EQ(ret, true);
}

/*
 * 用例名称: AddFilterRule
 * 前置条件：无
 * check点：设置过滤器规则
 */
TEST_F(NasArchiveRestoreTest, AddFilterRule)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    ApplicationResource applicationResource1;
    ApplicationResource applicationResource2;
    ApplicationResource applicationResource3;
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource1);
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource2);
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource3);
    ScanConfig scanConfig;
    scanConfig.copyId = "aa";
    scanConfig.jobId = "bb";
    
    EXPECT_NO_THROW(m_restoreJob->AddFilterRule(scanConfig));
}

/*
 * 用例名称: AddFilterRule2
 * 前置条件：无
 * check点：设置过滤器规则
 */
TEST_F(NasArchiveRestoreTest, AddFilterRule2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    ApplicationResource applicationResource1;
    applicationResource1.name = "/kk/";
    ApplicationResource applicationResource2;
    ApplicationResource applicationResource3;
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource1);
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource2);
    m_restoreJob->m_jobInfoPtr->restoreSubObjects.push_back(applicationResource3);
    ScanConfig scanConfig;
    scanConfig.copyId = "aa";
    scanConfig.jobId = "bb";
    
    EXPECT_NO_THROW(m_restoreJob->AddFilterRule(scanConfig));
}

static void Stub_PrintScannerStatistics_Void(void* obj)
{
    return;
}

static bool Stub_CreateSubTasksFromCtrlFile_False(void* obj)
{
    return false;
}

/*
 * 用例名称: MonitorScan
 * 前置条件：无
 * check点：监控扫描
 */
// TEST_F(NasArchiveRestoreTest, MonitorScan)
// {
//     AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
//     auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
//     m_restoreJob->SetJobInfo(jobInfoRestore);
//     m_restoreJob->InitInfo();

//     stub.set(ADDR(NasArchiveRestore, PrintScannerStatistics), Stub_PrintScannerStatistics_Void);
//     stub.set(ADDR(NasArchiveRestore, CreateSubTasksFromCtrlFile), Stub_CreateSubTasksFromCtrlFile_False);
//     EXPECT_NO_THROW(m_restoreJob->MonitorScan());
//     stub.reset(ADDR(NasArchiveRestore, PrintScannerStatistics));
//     stub.reset(ADDR(NasArchiveRestore, CreateSubTasksFromCtrlFile));
// }

static void Stub_ReportJobDetailsWithLabelAndErrcode_Void(void* obj)
{
    return;
}
/*
 * 用例名称: ReportScannerRunningStatus
 * 前置条件：无
 * check点：Report扫描运行时状态
 */
TEST_F(NasArchiveRestoreTest, ReportScannerRunningStatus)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set((void(HetroCommonService::*)(const JobLogLevel::type&, SubJobStatus::type, int, std::string, int64_t, std::string))ADDR(HetroCommonService, ReportJobDetailsWithLabelAndErrcode), Stub_ReportJobDetailsWithLabelAndErrcode_Void);
    bool ret = m_restoreJob->ReportScannerRunningStatus();
    EXPECT_EQ(ret, true);
    // stub.reset(ADDR(HetroCommonService, ReportJobDetailsWithLabelAndErrcode));

}

static bool Stub_ReportJobDetails_Bool(void* obj)
{
    return true;
}
/*
 * 用例名称: ReportScannerRunningStatus
 * 前置条件：无
 * check点：Report扫描运行时状态
 */
// TEST_F(NasArchiveRestoreTest, ReportScannerRunningStatus2)
// {
//     AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
//     auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
//     m_restoreJob->SetJobInfo(jobInfoRestore);
//     m_restoreJob->InitInfo();

//     m_restoreJob->m_lastScannerReportTime = PluginUtils::GetCurrentTimeInSeconds();
//     stub.set((void(HetroCommonService::*)(const JobLogLevel::type&, SubJobStatus::type, int, std::string, int64_t, std::string))ADDR(HetroCommonService, ReportJobDetails), Stub_ReportJobDetails_Bool);
//     bool ret = m_restoreJob->ReportScannerRunningStatus();
//     EXPECT_EQ(ret, true);
// }

/*
 * 用例名称: ReportScannerRunningStatus
 * 前置条件：无
 * check点：设置归档job状态成功
 */
TEST_F(NasArchiveRestoreTest, SetArchiveJobState)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    m_restoreJob->m_scanStatus = SCANNER_STATUS::COMPLETED;
    EXPECT_NO_THROW(m_restoreJob->SetArchiveJobState());
}

/*
 * 用例名称: ReportScannerRunningStatus
 * 前置条件：无
 * check点：设置归档job状态失败
 */
TEST_F(NasArchiveRestoreTest, SetArchiveJobState2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    m_restoreJob->m_scanStatus = SCANNER_STATUS::FAILED;
    EXPECT_NO_THROW(m_restoreJob->SetArchiveJobState());
}

/*
 * 用例名称: ReportScannerRunningStatus
 * 前置条件：无
 * check点：设置归档job状态
 */
TEST_F(NasArchiveRestoreTest, SetArchiveJobState3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    m_restoreJob->m_scanStatus = SCANNER_STATUS::ABORT_IN_PROGRESS;
    EXPECT_NO_THROW(m_restoreJob->SetArchiveJobState());
}

static bool Stub_CheckFilePathAndGetSrcFileList_False(void* obj)
{
    return false;
}

static bool Stub_CheckFilePathAndGetSrcFileList_True(void* obj, std::string srcDir, std::string dstDir,
    std::vector<std::string> &srcFileList)
{
    srcDir = "/user";
    dstDir = "/zz";
    srcFileList.emplace_back("aa");
    srcFileList.emplace_back("bb");
    return true;
}


static std::unique_ptr<Backup> Stub_CreateBackupInst_Nullptr(void* obj)
{
    return nullptr;
}

/*
 * 用例名称: CreateSubTasksFromCtrlFile
 * 前置条件：无
 * check点：创建子任务
 */
TEST_F(NasArchiveRestoreTest, CreateSubTasksFromCtrlFile)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    SubJobStatus::type jobStatus; 
    uint32_t subTaskType = 1;
    bool isFinal = true;
    stub.set(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList), Stub_CheckFilePathAndGetSrcFileList_False);

    bool ret = m_restoreJob->CreateSubTasksFromCtrlFile(jobStatus, subTaskType, isFinal);
    EXPECT_EQ(ret, false);
    stub.reset(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList));
}

/*
 * 用例名称: CreateSubTasksFromCtrlFile
 * 前置条件：无
 * check点：创建子任务
 */
//  gdb的1067行有问题！！！

// TEST_F(NasArchiveRestoreTest, CreateSubTasksFromCtrlFile2)
// {
//     AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
//     auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
//     m_restoreJob->SetJobInfo(jobInfoRestore);
//     m_restoreJob->InitInfo();
//     m_restoreJob->m_jobId = string("ss");
//     m_restoreJob->m_subJobId = string("ssmm");
//     // std::vector<std::string> m_srcFileList;
//     SubJobStatus::type jobStatus; 
//     uint32_t subTaskType = 1;
//     bool isFinal = false;
//     // m_restoreJob->CTRL_FILE_CNT = 0;
//     stub.set(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList), Stub_CheckFilePathAndGetSrcFileList_True);
    
//     stub.set(ADDR(NasArchiveRestore, SendJobReportForAliveness), Stub_CheckFilePathAndGetSrcFileList_True);
//     stub.set(ADDR(NasArchiveRestore, IsAbort), Stub_CheckFilePathAndGetSrcFileList_True);
//     // stub.set(ADDR(HetroCommonService, IsValidCtrlFile), Stub_CheckFilePathAndGetSrcFileList_False);

//     bool ret = m_restoreJob->CreateSubTasksFromCtrlFile(jobStatus, subTaskType, isFinal);
//     EXPECT_EQ(ret, true);
// }

/*
 * 用例名称: IdentifyFileReplaceStrategy
 * 前置条件：无
 * check点：验证FileReplaceStrategy
 */

TEST_F(NasArchiveRestoreTest, IdentifyFileReplaceStrategy)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    string strategy;
    strategy = "0";
    EXPECT_NO_THROW(m_restoreJob->IdentifyFileReplaceStrategy(strategy));
}

/*
 * 用例名称: IdentifyFileReplaceStrategy
 * 前置条件：无
 * check点：验证FileReplaceStrategy
 */

TEST_F(NasArchiveRestoreTest, IdentifyFileReplaceStrategy2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    
    string strategy;
    strategy = "1";
    EXPECT_NO_THROW(m_restoreJob->IdentifyFileReplaceStrategy(strategy));
}

/*
 * 用例名称: IdentifyFileReplaceStrategy
 * 前置条件：无
 * check点：验证FileReplaceStrategy
 */

TEST_F(NasArchiveRestoreTest, IdentifyFileReplaceStrategy3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    
    string strategy;
    strategy = "2";
    EXPECT_NO_THROW(m_restoreJob->IdentifyFileReplaceStrategy(strategy));
}

/*
 * 用例名称: IdentifyFileReplaceStrategy
 * 前置条件：无
 * check点：验证FileReplaceStrategy
 */

TEST_F(NasArchiveRestoreTest, IdentifyFileReplaceStrategy4)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();
    
    string strategy;
    strategy = "3";
    EXPECT_NO_THROW(m_restoreJob->IdentifyFileReplaceStrategy(strategy));
}

static bool Stub_CheckFilePathAndGetSrcFileList_True2(void* obj)
{
    return true;
}
/*
 * 用例名称: CreateSubTasksFromCtrlFile
 * 前置条件：无
 * check点：创建子任务
 */

TEST_F(NasArchiveRestoreTest, CreateSubTasksFromCtrlFile3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    SubJobStatus::type jobStatus; 
    uint32_t subTaskType = 1;
    bool isFinal = true;
    stub.set(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set((int(HetroCommonService::*)(std::vector<SubJob>&, std::vector<std::string>&))ADDR(HetroCommonService, CreateSubTask), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->CreateSubTasksFromCtrlFile(jobStatus, subTaskType, isFinal);
    EXPECT_NE(ret, SUCCESS);
    stub.reset(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList));
    stub.reset((int(HetroCommonService::*)(std::vector<SubJob>&, std::vector<std::string>&))ADDR(HetroCommonService, CreateSubTask));

}

/*
 * 用例名称: CreateSubTasksFromCtrlFile
 * 前置条件：无
 * check点：创建子任务
 */

TEST_F(NasArchiveRestoreTest, CreateSubTasksFromCtrlFile4)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    SubJobStatus::type jobStatus; 
    uint32_t subTaskType = 1;
    bool isFinal = true;
    stub.set(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set((int(HetroCommonService::*)(std::vector<SubJob>&, std::vector<std::string>&))ADDR(HetroCommonService, CreateSubTask), Stub_CheckFilePathAndGetSrcFileList_True2);
    bool ret = m_restoreJob->CreateSubTasksFromCtrlFile(jobStatus, subTaskType, isFinal);
    EXPECT_EQ(ret, true);
    stub.reset(ADDR(NasArchiveRestore, CheckFilePathAndGetSrcFileList));
    stub.reset((int(HetroCommonService::*)(std::vector<SubJob>&, std::vector<std::string>&))ADDR(HetroCommonService, CreateSubTask));
}

/*
 * 用例名称: GenerateSubJobList
 * 前置条件：无
 * check点：生成子任务list失败
 */

TEST_F(NasArchiveRestoreTest, GenerateSubJobList)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    SubJob subJob;
    std::vector<SubJob> subJobList;
    subJobList.push_back(subJob);
    subJobList.push_back(subJob);
    subJobList.push_back(subJob);
    std::vector<std::string> ctrlFileList;
    ctrlFileList.push_back("a");
    ctrlFileList.push_back("b");
    std::string dstCtrlFileRelPath;
    dstCtrlFileRelPath = "m";
    std::string ctrlFileFullPath;
    ctrlFileFullPath = "m";
    m_restoreJob->m_jobId = string("ss");
    stub.set(ADDR(HetroCommonService, InitSubTask), Stub_CheckFilePathAndGetSrcFileList_False);
    bool ret = m_restoreJob->GenerateSubJobList(subJobList, ctrlFileList, dstCtrlFileRelPath, ctrlFileFullPath);
    EXPECT_EQ(ret, false);
    stub.reset(ADDR(HetroCommonService, InitSubTask));
}

/*
 * 用例名称: GenerateSubJobList
 * 前置条件：无
 * check点：生成子任务list成功
 */

TEST_F(NasArchiveRestoreTest, GenerateSubJobList2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    SubJob subJob;
    std::vector<SubJob> subJobList;
    subJobList.push_back(subJob);
    subJobList.push_back(subJob);
    subJobList.push_back(subJob);
    std::vector<std::string> ctrlFileList;
    ctrlFileList.push_back("a");
    ctrlFileList.push_back("b");
    std::string dstCtrlFileRelPath;
    dstCtrlFileRelPath = "m";
    std::string ctrlFileFullPath;
    ctrlFileFullPath = "m";
    m_restoreJob->m_jobId = string("ss");
    stub.set(ADDR(HetroCommonService, InitSubTask), Stub_IsAbort_True);
    bool ret = m_restoreJob->GenerateSubJobList(subJobList, ctrlFileList, dstCtrlFileRelPath, ctrlFileFullPath);
    EXPECT_EQ(ret, true);
    stub.reset(ADDR(HetroCommonService, InitSubTask));
}

/*
 * 用例名称: ExecuteSubJobInner
 * 前置条件：无
 * check点：执行子任务失败
 */

TEST_F(NasArchiveRestoreTest, ExecuteSubJobInner)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->ExecuteSubJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));

}

/*
 * 用例名称: ExecuteSubJobInner
 * 前置条件：无
 * check点：初始化ArchiveClient失败
 */

TEST_F(NasArchiveRestoreTest, ExecuteSubJobInner2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->ExecuteSubJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
    stub.reset(ADDR(NasArchiveRestore, InitArchiveClient));
    
}

/*
 * 用例名称: ExecuteSubJobInner
 * 前置条件：无
 * check点：初始化SubBackupJobResources失败
 */

TEST_F(NasArchiveRestoreTest, ExecuteSubJobInner3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitSubBackupJobResources), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->ExecuteSubJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
    stub.reset(ADDR(NasArchiveRestore, InitArchiveClient));
    stub.reset(ADDR(NasArchiveRestore, InitSubBackupJobResources));

}

/*
 * 用例名称: ExecuteSubJobInner
 * 前置条件：无
 * check点：StartRestore失败
 */

TEST_F(NasArchiveRestoreTest, ExecuteSubJobInner4)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitSubBackupJobResources), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, StartRestore), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->ExecuteSubJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
    stub.reset(ADDR(NasArchiveRestore, InitArchiveClient));
    stub.reset(ADDR(NasArchiveRestore, InitSubBackupJobResources));
    stub.reset(ADDR(NasArchiveRestore, StartRestore));
}

static SubJobStatus::type Stub_MonitorRestore_Void(void* obj)
{
    return SubJobStatus::COMPLETED;
}

static void Stub_ReportTapeNotSupportDirectRestore(void* obj)
{
    return;
}

/*
 * 用例名称: ExecuteSubJobInner
 * 前置条件：无
 * check点：执行子任务成功
 */

TEST_F(NasArchiveRestoreTest, ExecuteSubJobInner5)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, ReportTapeNotSupportDirectRestore), Stub_ReportTapeNotSupportDirectRestore);
    stub.set(ADDR(NasArchiveRestore, InitSubBackupJobResources), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, StartRestore), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, MonitorRestore), Stub_MonitorRestore_Void);
    stub.set(ADDR(NasArchiveRestore, CheckConnect), Stub_CheckConnectSMB);
    int ret = m_restoreJob->ExecuteSubJobInner();
    EXPECT_EQ(ret, Module::SUCCESS);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
    stub.reset(ADDR(NasArchiveRestore, InitArchiveClient));
    stub.reset(ADDR(NasArchiveRestore, InitSubBackupJobResources));
    stub.reset(ADDR(NasArchiveRestore, MonitorRestore));
    stub.reset(ADDR(NasArchiveRestore, StartRestore));
    stub.reset(ADDR(NasArchiveRestore, CheckConnect));
}

/*
 * 用例名称: CheckFilePathAndGetSrcFileList
 * 前置条件：无
 * check点：检查FilePath是否存在，获取SrcFileList失败
 */

TEST_F(NasArchiveRestoreTest, CheckFilePathAndGetSrcFileList)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    std::string srcDir;
    std::string dstDir;
    std::vector<std::string> srcFileList;

    stub.set(ADDR(Module, CFile::DirExist), Stub_CheckFilePathAndGetSrcFileList_False);

    bool ret = m_restoreJob->CheckFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList);
    EXPECT_EQ(ret, false);
    stub.reset(ADDR(Module, CFile::DirExist));
}

/*
 * 用例名称: CheckFilePathAndGetSrcFileList2
 * 前置条件：无
 * check点：检查FilePath是否存在，获取SrcFileList失败
 */

TEST_F(NasArchiveRestoreTest, CheckFilePathAndGetSrcFileList2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    std::string srcDir;
    std::string dstDir;
    std::vector<std::string> srcFileList;

    stub.set(ADDR(Module, CFile::DirExist), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(PluginUtils, GetFileListInDirectory), Stub_CheckFilePathAndGetSrcFileList_False);

    bool ret = m_restoreJob->CheckFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList);
    EXPECT_EQ(ret, false);
    stub.reset(ADDR(Module, CFile::DirExist));
    stub.reset(ADDR(PluginUtils, GetFileListInDirectory));
}

/*
 * 用例名称: CheckFilePathAndGetSrcFileList3
 * 前置条件：无
 * check点：检查FilePath是否存在，获取SrcFileList成功
 */

TEST_F(NasArchiveRestoreTest, CheckFilePathAndGetSrcFileList3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    std::string srcDir;
    std::string dstDir;
    std::vector<std::string> srcFileList;

    stub.set(ADDR(Module, CFile::DirExist), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(PluginUtils, GetFileListInDirectory), Stub_CheckFilePathAndGetSrcFileList_True2);

    bool ret = m_restoreJob->CheckFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList);
    EXPECT_EQ(ret, true);
    stub.reset(ADDR(Module, CFile::DirExist));
    stub.reset(ADDR(PluginUtils, GetFileListInDirectory));
}

/*
 * 用例名称: PostJobInner
 * 前置条件：无
 * check点：初始化信息失败
 */

TEST_F(NasArchiveRestoreTest, PostJobInner)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->PostJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
}

/*
 * 用例名称: PostJobInner
 * 前置条件：无
 * check点：初始化归档客户端失败
 */

TEST_F(NasArchiveRestoreTest, PostJobInner2)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_False);
    int ret = m_restoreJob->PostJobInner();
    EXPECT_EQ(ret, Module::FAILED);
    stub.reset(ADDR(NasArchiveRestore, InitInfo));
    stub.reset(ADDR(NasArchiveRestore, InitArchiveClient));
}

static int Stub_EndRecover_FAILED(void* obj)
{
    return FAILED;
}
/*
 * 用例名称: PostJobInner
 * 前置条件：无
 * check点：终止恢复失败
 */

TEST_F(NasArchiveRestoreTest, PostJobInner3)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    // stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    m_restoreJob->m_jobId = "a";
    m_restoreJob->m_copyId = "ab";
    string jobId = "a";
    string copyId = "a";
    m_restoreJob->m_archiveClient = std::make_shared<ArchiveClient>(jobId, copyId);
    typedef int (*fptr)(ArchiveClient*);
    fptr A_foo = (fptr)(&ArchiveClient::EndRecover);
    stub.set(A_foo, Stub_EndRecover_FAILED);

    int ret = m_restoreJob->PostJobInner();
    EXPECT_EQ(ret, Module::FAILED);
}

static int Stub_EndRecover_SUCCESS(void* obj)
{
    return SUCCESS;
}
/*
 * 用例名称: PostJobInner
 * 前置条件：无
 * check点：终止恢复失败
 */

TEST_F(NasArchiveRestoreTest, PostJobInner4)
{
    AppProtect::RestoreJob restoreJob = RestoreJobInfoSetUp(false, "NasShare");
    auto jobInfoRestore = make_shared<JobCommonInfo>(make_shared<RestoreJob>(restoreJob));
    m_restoreJob->SetJobInfo(jobInfoRestore);
    m_restoreJob->InitInfo();

    stub.set(ADDR(NasArchiveRestore, InitInfo), Stub_CheckFilePathAndGetSrcFileList_True2);
    stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    // stub.set(ADDR(NasArchiveRestore, InitArchiveClient), Stub_CheckFilePathAndGetSrcFileList_True2);
    m_restoreJob->m_jobId = "a";
    m_restoreJob->m_copyId = "ab";
    string jobId = "a";
    string copyId = "a";
    m_restoreJob->m_archiveClient = std::make_shared<ArchiveClient>(jobId, copyId);
    typedef int (*fptr)(ArchiveClient*);
    fptr A_foo = (fptr)(&ArchiveClient::EndRecover);
    stub.set(A_foo, Stub_EndRecover_SUCCESS);

    typedef int (*fptr)(ArchiveClient*);
    A_foo = (fptr)(&ArchiveClient::DisConnect);
    stub.set(A_foo, Stub_EndRecover_FAILED);

    int ret = m_restoreJob->PostJobInner();
    EXPECT_EQ(ret, Module::SUCCESS);
}
